/**********************************************
/ file : ifft.sc
/ Author : Jungmin Park
/ Date : 4/25/2011 
/ Specification Model of Data Storage 
***********************************************/
#include <math.h>
#include <stdio.h>
import "c_double_handshake";

#define PI 3.141592

behavior ifft (i_receiver IR1, i_receiver IR2, i_sender IS1, i_sender IS2)
{
  float x_re [16];
  float x_im [16];
  float temp1 = 0;
  float temp2 = 0;
  int i;
  int j;
  
  void main (void)
  {
     for (i=0; i<16; i++)
     {
        IR1.receive (x_re+i, sizeof(float));
        IR2.receive (x_im+i, sizeof(float));
     }
     
     for (i=0; i < 16; i++)
	   {
		    for (j=0; j < 16 ; j++)
		    {
			     // Inverse FFT
			     temp1 += (*(x_re+j)*cosf(2*PI*i*j/16)-*(x_im+j)*sinf(2*PI*i*j/16));      //  Real value
		       temp2 += (*(x_re+j)*sinf(2*PI*i*j/16)+*(x_im+j)*cosf(2*PI*i*j/16));      //  Imaginary value

	     	}
	     	temp1 = temp1/16;
		    temp2 = temp2/16;
		    IS1.send (&temp1, sizeof(temp1));
		    IS2.send (&temp2, sizeof(temp2));
		    temp1 = 0;
		    temp2 = 0;
		 }
	}
};     
     
  